package com.penngo.gui.dfdiff.view;

import com.penngo.gui.dfdiff.utils.*;
import org.jdesktop.swingx.JXHyperlink;

import javax.swing.*;
import java.awt.*;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;

public class AboutDialog extends JDialog {
    private Logger log = LogUtils.getLogger(AboutDialog.class);
    public AboutDialog(){
        this.setLayout(new GridBagLayout());
        initPanel();
        setIconImage(ImgUtil.getIcon(AppInfo.Logo).getImage());
//        setSize((int)(ScreenUtil.getScreenWidth() * 0.5), (int)(ScreenUtil.getScreenHeight() * 0.5));
        setSize(300, 200);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        setModal(true);
        setVisible(true);
    }

    private void initPanel(){
        try{
            Container container = this.getContentPane();
            JLabel appLabel = new JLabel(AppInfo.Name + " " + AppInfo.Version);
            int row = 0;
            container.add(appLabel, new GB(0,row,1,1).setInsets(10));


            JLabel homeLabel = new JLabel("主页:");
            JXHyperlink homeLink = new JXHyperlink();
            homeLink.setURI(new URI("https://gitee.com/penngo/dfdiff"));
            JPanel linkPanel = new JPanel(new GridBagLayout());
            linkPanel.add(homeLabel, new GB(0,0,1,1));
            linkPanel.add(homeLink, new GB(1,0,1,1));
            linkPanel.add(new JPanel(), new GB(2,0,1,1).setFill(GB.BOTH).setWeight(100,0));
            container.add(linkPanel, new GB(0, ++row, 2, 1).setFill(GB.BOTH).setWeight(100,0).setInsets(10));

            container.add(new JPanel(), new GB(0,++row,2,1).setFill(GB.BOTH).setWeight(100,100));
        }
        catch(Exception e){
            log.log(Level.SEVERE, "initPanel error=====", e);
        }

    }

    public static void  Show(){
        AboutDialog dialog = new AboutDialog();

    }
}
